﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>@ViewBag.webFrontTitle</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link href="~/layuiadmin/layui/css/layui.css" rel="stylesheet" />
    <link href="~/layuiadmin/style/admin.css" rel="stylesheet" />
    <link href="~/layuiadmin/style/login.css" rel="stylesheet" />
    <script src="~/js/CommonHelper.js"></script>
    <link href="~/css/user.css" rel="stylesheet" />
    <script>
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null) return unescape(r[2]); return null; //返回参数值
        }
    </script>
</head>
<body class="login-box">
    <div class="layui-card-body languaue">
        <button class="layui-btn demo-dropdown-base" id="languageSelect">
            <span><i class="layui-icon layui-icon-website"></i></span>
        </button>
    </div>
    <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
        <div class="layadmin-user-login-main">
            <div class="layadmin-user-login-box layadmin-user-login-header">
                <h2>@ViewBag.sitename</h2>
            </div>
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form  layui-text">
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-username"></label>
                    <input type="text" name="email" id="email" placeholder="email" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password"></label>
                    <input type="password" name="userPwd" id="userPwd" placeholder="userPwd" class="layui-input">
                </div>
                <div class="layui-form-item">
                    <input type="checkbox" id="remember" name="remember" lay-skin="primary" title="remember">
                    <a id="forget" style="float: right; margin-top: 7px;">忘记密码</a>
                </div>
                <div class="layui-form-item">
                    <button id="login" class="layui-btn layui-btn-fluid" lay-submit lay-filter="login" lay-event="login">立即登入</button>
                </div>
                <div class="layui-form-item demo-login-other">
                    <a id="register" lay-event="register">注册帐号</a>
                </div>
            </div>
        </div>
    </div>

    <script src="~/layuiadmin/layui/layui.js"></script>
    <script>
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'user', 'dropdown'], function () {
            var $ = layui.$
                , form = layui.form
                , dropdown = layui.dropdown
                , router = layui.router();
            form.render();
            document.onkeydown = function (e) {
                var ev = document.all ? window.event : e;
                if (ev.keyCode == 13) {
                    $('#login-submit').trigger("click");
                    return false;
                }
            }

            //多语言下拉框
            dropdown.render({
                elem: '#languageSelect', // 绑定元素选择器，此处指向 class 可同时绑定多个元素
                data: [{
                    title: '中文',
                    id: 'user-zh-CN',
                    href: '?language=user-zh-CN'
                }, {
                    title: 'English',
                    id: 'user-en-US',
                    href: '?language=user-en-US'
                }],
                click: function (obj) {
                    var selectedValue = $(this).val();
                    getLanguages(layui, selectedValue);
                    $('#forget').attr('href', '/Login/Forget?language=' + language)
                    $('#register').attr('href', '/Login/Register?language=' + language)
                }
            });

            //提交
            form.on('submit(login)', function (obj) {

                //请求登入接口
                $.ajax({
                    type: "POST",
                    url: "/Login/Login",
                    data: obj.field, // 你的formid
                    error: function (request) {
                        console.log("请求超时");
                    },
                    success: function (res) {
                        if (res.code == 0) {
                            top.ShowMessageByKey(layui, res.msg, 6, 1000, function () {
                                if (language) {
                                    window.location.href = '/Home/Index?language=' + language;
                                } else {
                                    window.location.href = '/Home/Index?language=user-zh-CN'
                                }
                            });
                        } else {
                            top.ShowMessageByKey(layui, res.msg, 0, 1000);
                        }
                    }
                });
            });

            var language = getUrlParam("language");
            $(document).ready(function () {
                if (language) {
                    getLanguages(layui, language);
                    $('#forget').attr('href', '/Login/Forget?language=' + language)
                    $('#register').attr('href', '/Login/Register?language=' + language)
                } else {
                    getLanguages(layui, 'user-zh-CN');
                    $('#forget').attr('href', '/Login/Forget?language=user-zh-CN')
                    $('#register').attr('href', '/Login/Register?language=user-zh-CN')
                }
            });
        });
    </script>
</body>
</html>